// pages/home/home.js
//获取全局数据
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      curous:[],
      type_index:0,
      type:[
        {
          name:"全部",
          id:0
        }
      ],
      good:[],
      notice:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   

      this.getCurous();
    this.getType();
    this.getNotice();
    this.getGood();
  
  },
//跳转到公告详情
goDetail(e){
  console.log(e)
  var id=e.currentTarget.dataset.gx;
  wx.navigateTo({
    url: '/pages/notice/notice?id='+id,
  })


},
  //获取商品
  getGood(){
    var that = this;
    wx.request({
      url: app.globalData.BaseUrl + '/shop/goods/list',
      success: function (res) {
       
        that.setData({
          good: res.data.data
        })
      }
    })

  },
  //获取公告
  getNotice:function(){
    var that = this;
    wx.request({
      url: app.globalData.BaseUrl + '/notice/list',
      success: function (res) {
        console.log(res)
        that.setData({
          notice: res.data.data
        })
      }
    }) 

  },
  //获取轮播数据
  getCurous:function(){
    var that=this;
    wx.request({
      url: app.globalData.BaseUrl+'/banner/list',
      success:function(res){
      
          that.setData({
            curous:res.data.data
          })
      }
    })
  },
  //获取商品类别
  getType:function(){
    var that = this;
    wx.request({
      url: app.globalData.BaseUrl + '/shop/goods/category/all',
      success: function (res) {
       
        var typeall=that.data.type;
        typeall = typeall.concat(res.data.data)
        that.setData({
          type: typeall
        })
      }
    })

  },
  // 点击类型事件
  typebind:function(e){
    var id = e.currentTarget.dataset.id;
    var index = e.currentTarget.dataset.index;
    var that=this;
    this.setData({
      type_index:index
    })
    wx.request({
      url: app.globalData.BaseUrl + '/shop/goods/list',
     
      data: { categoryId:id},
      success: function (res) {
          console.log(res.data)
          if(res.data.code==700){
            that.setData({
              good: []
            })
          }else{
            that.setData({
              good: res.data.data
            })
          }
          
      }
    })



  },
  // 跳转到商品详情
  shopDetail:function(e){
      var id=e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/shop/shop?id='+id,
      })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})